#include "Tile.h"
#include "InputHandler.h"
#include "Defines.h"


Tile::Tile(const LoadedParams* Params, int animationSpeed, int numFrames) : AnimatedGraphic(Params, animationSpeed, numFrames), selected(false)
{
	mainTexture = Params->getTextureID();
	hoverTexture = "grid";
}


void Tile::Draw()
{
	AnimatedGraphic::Draw();
}

void Tile::Update()
{
	handleOnClick();
	AnimatedGraphic::Update();
}

void Tile::Shutdown()
{
	AnimatedGraphic::Shutdown();
}

bool Tile::isMouseOver()
{
	Vector2D* pMousePos = InputHandler::Instance()->getMousePosition();

	if(pMousePos->getX() < (position.getX() + Width) 
	&& pMousePos->getX() > position.getX()
	&& pMousePos->getY() < (position.getY() + Height) 
	&& pMousePos->getY() > position.getY())
	{
		return true;
	}
	return false;
}

bool Tile::isSelected()
{
	return selected;
}

void Tile::handleOnClick()
{
	if(isMouseOver())
	{
		if(InputHandler::Instance()->Clicked())
			selected = !selected;
	}
}

bool Tile::isActive()
{
	return AnimatedGraphic::isActive();
}